using Game.Main.Model;
using Game.XH;
using SimpleJSON;
using UnityEngine;

namespace Game.Component
{
	public class ScannerDisplayerItem : BaseItem
	{
		private Transform displayer;

		private Vector2 originalPos;

		private float curX;

		private float curY;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			displayer = model.Find("Displayer");
			displayer.SetLocalZ(1E-05f);
			originalPos = displayer.localPosition;
			curX = data.modelX;
			curY = data.modelY;
			if (curX != 0f || curY != 0f)
			{
				displayer.localPosition = originalPos + new Vector2(curX, curY);
			}
		}

		public void IsShowDisplayer(bool val)
		{
			if (val)
			{
				displayer.GetComponent<SpriteRenderer>().color = new Color(255f, 255f, 255f, 255f);
			}
			else
			{
				displayer.GetComponent<SpriteRenderer>().color = new Color(0f, 0f, 0f, 255f);
			}
		}

		public void SetRelativePosition(float x, float y)
		{
			curX = (0f - x) * 0.3f;
			curY = (0f - y) * 0.91f;
			displayer.localPosition = originalPos + new Vector2(curX, curY);
		}

		public override void PackData(JSONObject obj)
		{
			base.PackData(obj);
			obj["34"] = curX.ToString("F3");
			obj["39"] = curY.ToString("F3");
		}
	}
}
